package com.gscitysfy.cus.drain.modules.duty.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;

import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.duty.entity.MoperDutyRlLog;
import com.gscitysfy.cus.drain.modules.duty.service.IMoperDutyRlLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-03-28 15:38:59
 */
@RestController
@RequestMapping("/duty/log")
public class MoperDutyRlLogController {
    @Autowired
    IMoperDutyRlLogService moperDutyRlLogService;

    /**
     * 新增
     *
     * @param moperDutyRlLog
     * @return
     */
    @PostMapping("/add")
    public Result add(MoperDutyRlLog moperDutyRlLog) {
        moperDutyRlLogService.addMoperDutyRlLog(moperDutyRlLog);
        return Result.success();
    }


    /**
     * 修改
     *
     * @param moperDutyRlLog
     * @return
     */
    @PostMapping("/update")
    public Result update(MoperDutyRlLog moperDutyRlLog) {
        int i = moperDutyRlLogService.updateMoperDutyRlLog(moperDutyRlLog);
        if (i > 0) {
            return Result.success();
        } else {
            return Result.failure("当前状态不可修改");
        }
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(String ids) {
        if (moperDutyRlLogService.deleteMoperDutyRlLog(ids)) {
            return Result.success();
        } else {
            return Result.failure("当前状态不可删除");
        }
    }


    /**
     * 详情
     */
    @PostMapping("/detail")
    @DictTranslation({@FieldParam(dictType = DicConstant.DUTY_RECORD_STATUS, targetField = "coamClassessStatus")})
    public Result detail(String id) {
        MoperDutyRlLog moperDutyRlLog = moperDutyRlLogService.detailMoperDutyRlLog(id);
        return Result.content(moperDutyRlLog);

    }


    /**
     * 列表
     *
     * @return
     */
    @GetMapping("/all")
    @DictTranslation({@FieldParam(dictType = DicConstant.DUTY_RECORD_STATUS, targetField = "coamClassessStatus"),
                    @FieldParam(dictType = DicConstant.LOG_RUN_STATUS, targetField = "coamRunStatus"),
                    @FieldParam(dictType = DicConstant.DUTY_TYPE, targetField = "peopletype")
    })
    public Result getAll(Page<MoperDutyRlLog> page, String startTime, String endTime, String rylx,String bc, String zbry) {
        return Result.content(moperDutyRlLogService.getAll(page, startTime, endTime, rylx, bc, zbry));
    }

    /**
     * 人员列表
     * @return
     */
    @GetMapping("/allPeople")
    public Result allPeople() {
        return Result.content(moperDutyRlLogService.allPeople());
    }

    /**
     * 班次列表
     *
     * @return
     */
    @GetMapping("/allClassess")
    public Result allClassess(String coamClassessType,String coamClassessCode, @RequestParam(required = false) Long coamClassessStatu) {
        return Result.content(moperDutyRlLogService.allClassess(coamClassessType, coamClassessCode, coamClassessStatu));
    }

    /**
     * 审核
     *
     * @return
     */
    @PostMapping("/audit")
    public Result audit(String ids,String coamLogRemark,String coamClassessStatus) {
        int i = moperDutyRlLogService.audit(ids,coamLogRemark,coamClassessStatus);
        if (i > 0) {
            return Result.success();
        } else {
            return Result.failure("当前状态不可审核");
        }
    }


    /**
     * 记录查看
     *
     * @return
     */
    @GetMapping("/record")
    public Result record(String id) {
        return Result.content(moperDutyRlLogService.record(id));
    }

    /**
     * 记录下载
     *
     * @return
     */
    @GetMapping ("/recordDownload")
    public void recordDownload(@RequestParam("ids") List<String> listId, HttpServletResponse response) {
        moperDutyRlLogService.recordDownload(listId, response);
    }

    /**
     * 记录下载
     *
     * @return
     */
    @GetMapping("/people")
    public Result people() {
        return Result.content(moperDutyRlLogService.people());

    }
}
